#!/bin/bash

set -e

# This release script assumes that you have codekitchen/homebrew-dinghy checked
# out as a sibling to this dinghy checkout.

VERSION=$1
TODAY=$(date "+%Y-%m-%d")

: ${VERSION:?"Need to specify a version e.g. 2.0.1"}

sed -i '' "s/DINGHY_VERSION=.*/DINGHY_VERSION='$VERSION'/g" cli/dinghy/version.rb
sed -i '' $'s/## Unreleased/## Unreleased\
\
## '"$VERSION - $TODAY/g" CHANGELOG.md

git commit -am "v$VERSION"
git tag "v$VERSION"
REF=$(git show-ref -s "v$VERSION")
git push origin master:master
git push origin "v$VERSION"

pushd ../homebrew-dinghy
sed -i '' 's|  url ".*|  url "https://github.com/codekitchen/dinghy.git", :tag => "v'$VERSION'", :revision => "'$REF'"|' Formula/dinghy.rb
git commit -am "release v$VERSION"
git push origin master:master
popd
